package com.example.task.controller;


import com.example.task.dto.CartDto;
import com.example.task.dto.CarttNumDto;
import com.example.task.service.intf.CartService;
import com.example.task.vo.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/api/cart/")
@Api(value = "实现购物车相关操作",tags = "实现购物车相关操作")
public class CartController {
    @Autowired
    private CartService service;

    //加入
    @PostMapping("add.do")
    public R add(@RequestBody CartDto dto){
        return service.save(dto);
    }
    //改变数量
    @PostMapping("change.do")
    public R change(@RequestBody CarttNumDto dto){
        return service.change(dto);
    }
    //查询
    @GetMapping("all.do")
    public R all(long uid){
        return service.queryMy(uid);
    }
    //删除
    @GetMapping("del.do")
    public R del(long id){
        return service.del(id);
    }

    @PostMapping("items.do")
    public R items(@RequestBody int[] ids){
        return service.queryIds(ids);
    }
}
